import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 分类列表
    catelist: []
  },
  mutations: {
    getCates(state, catelist) {
      state.catelist = catelist
    }
  },
  actions: {
    async getCates(context) {
      const { data: res } = await axios.get('categories', {
        params: {
          type: 3
        }
      })
        .catch(error => console.log(error))
      if (res.meta.status === 200) {
        context.commit('getCates', res.data)
      }
    }
  }
})
